package com.zoryang.commonutils

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import androidx.annotation.Keep
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.BuildConfig
import com.orhanobut.logger.Logger

/**
 * @author Morphling
 */
@Keep
@SuppressLint("StaticFieldLeak")
object Operator {
    var context: Context? = null

    private fun init(context: Application, isLog: Boolean) {
        this.context = context
        initLogger(isLog)
    }

    private fun initLogger(isLog: Boolean) {
        Logger.addLogAdapter(object : AndroidLogAdapter() {
            override fun isLoggable(priority: Int, tag: String?): Boolean {
                return isLog
            }
        })
    }

    class Builder(private val context: Application) {

        private var isLog: Boolean = false

        fun isLog(isLog: Boolean): Builder {
            this.isLog = isLog
            return this
        }

        fun build() {
            init(context, isLog)
        }
    }
}